package com.liy.supercloud.ssoserver.feign;

import com.liy.framework.common.extvo.ResultVO;
import com.liy.supercloud.ssoserver.vo.SysLoginLog;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class SystemClientFallbackFactory implements FallbackFactory<SystemFeignClient> {
    private static final Logger log = LoggerFactory.getLogger(SystemClientFallbackFactory.class);

    public SystemClientFallbackFactory() {
    }

    public SystemFeignClient create(final Throwable e) {
        log.info("sys feign fallback; reason was: {}", e.getMessage());
        log.error(e.getMessage(), e);
        return new SystemFeignClient() {
            public ResultVO addLoginLog(SysLoginLog log) throws Exception {
                ResultVO resultVO = new ResultVO();
                resultVO.setMessage("系统服务异常：" + e.getMessage());
                resultVO.setStatus("500");
                resultVO.setSuccess(false);
                return resultVO;
            }

            public ResultVO queryUserRoleStation(String userId) throws Exception {
                ResultVO resultVO = new ResultVO();
                resultVO.setMessage("系统服务异常：" + e.getMessage());
                resultVO.setStatus("500");
                resultVO.setSuccess(false);
                return resultVO;
            }

            public ResultVO queryRolePermission(String roleId) throws Exception {
                ResultVO resultVO = new ResultVO();
                resultVO.setMessage("系统服务异常：" + e.getMessage());
                resultVO.setStatus("500");
                resultVO.setSuccess(false);
                return resultVO;
            }

            public ResultVO querySharedPermission(String sysId) throws Exception {
                ResultVO resultVO = new ResultVO();
                resultVO.setMessage("系统服务异常：" + e.getMessage());
                resultVO.setStatus("500");
                resultVO.setSuccess(false);
                return resultVO;
            }

            public ResultVO queryUserByAccount(String account) throws Exception {
                ResultVO resultVO = new ResultVO();
                resultVO.setMessage("系统服务异常：" + e.getMessage());
                resultVO.setStatus("500");
                resultVO.setSuccess(false);
                return resultVO;
            }
        };
    }
}
